import React, { useState } from 'react'
import { isIpInPending, isUser, PendingMt } from '../../../../translator'

export const useIpTip = (item: PendingMt) => {
	let [show, setShow] = useState(false)
	let [position, setPosition] = useState({ top: 0, left: 0 }) //ip tip位置
	const handleShowIpTip = (flag: boolean) => {
		// ip类显示tip
		if (isUser(item) && isIpInPending(item.ip)) {
			setShow(flag)
		}
	}
	const handleSetPosition = (e: React.MouseEvent) => {
		if (isUser(item) && isIpInPending(item.ip)) {
			setPosition({ top: e.clientY + 15, left: e.clientX + 10 })
		}
	}
	return [
		{ show, handleShowIpTip },
		{ position, handleSetPosition },
	] as const
}
